package com.neusoft.elmboot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.neusoft.elmboot.interceptor.LoginInsterceptor;

/**
 * 
 * @author chens
 *
 */
@Configuration
public class MvcConfig {
	@Bean
	public WebMvcConfigurer webMvcConfigurer() {
		return new WebMvcConfigurer() {
			@Override
			public void addResourceHandlers(ResourceHandlerRegistry registry) {
				registry.addResourceHandler("/upload/**").addResourceLocations("file:D:/Download/upload/");
			}

			@Override
			public void addInterceptors(InterceptorRegistry registry) {

				// 注册TestInterceptor拦截器
				InterceptorRegistration registration = registry.addInterceptor(new LoginInsterceptor());
				registration.addPathPatterns("/**"); // 所有路径都被拦截
				registration.excludePathPatterns( // 添加不拦截路径
						"/sys/admin/login", // 登录
						"/validatecode", //验证码不能拦
						"/login.html", //登录页面不能拦
						"/js/**", // js静态资源
						"/images/**", // image静态资源
						"/upload/**" // 上传页面不能拦截
						);
			}

		};
	}
}